<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<title>guige</title>
<link rel="stylesheet" type="text/css" href="../../css/index.css" />
<style>
	html,body{width:100%;height: 100%; overflow: hidden; background: transparent;}
	.showbox-bg{background: rgba(0,0,0,0.5);position:fixed;top: 0;bottom: 0;left: 0;right: 0;z-index: 1;animation:fadeIn 1s;-webkit-animation:fadeIn 1s;}
	.showbox{
	    background:#fff;position:fixed;left: 0;right: 0;bottom: 0;z-index:2;
	    display: flex;flex-direction: column; animation:updown 0.1s;-webkit-animation:updown 0.1s;
	}
	.showbox .boxbar{height: 55px; overflow: hidden;position: relative;}
	.showbox .boxbar .title{text-align: center;line-height: 55px;font-size: 16px;}
	.showbox .boxbar .close{height: 55px;width: 55px;align-items: center;justify-content: center;position: absolute;top: 0;right: 0;}
	.showbox .boxbar .close img{width: 16px;height: 16px;}
	/* showlist */
	.showlist{ overflow-y: auto; height:100px; padding: 0px 15px;color: #333333;align-items: center;}
	.showlist .share-one{padding: 0 20px;box-sizing: border-box;flex-direction: column;justify-content: center;}
	.showlist .share-one .img-box{width: 40px;height: 40px;}
	.showlist .share-one .img-box img{display: block;width: 100%;line-height: 0;}
	.showlist .share-one .text{line-height: 30px;text-align: center;}
	.btn{width: 100%;height: 50px;text-align: center;line-height: 50px;background: #F6F6F6;}

</style>
</head>
 <body>

	<div class="showbox-bg" tapmode onclick="closeClick();"></div>
    <div class="showbox">
        <div class="boxbar border-bottom">
        	<div class="title">分享到</div>
        </div>
        <div class="showlist flex">
        	<div class="share-one flex" data-type="wx" tapmode onclick="wrapClick(this)">
        		<div class="img-box"><img src="../../image/main/dl3.png"/></div>
        		<div class="text">微信</div>
        	</div>
			<div class="share-one flex" data-type="wxp" tapmode onclick="wrapClick(this)">
        		<div class="img-box"><img src="../../image/main/dl4.png"/></div>
        		<div class="text">朋友圈</div>
        	</div>
        	<div class="share-one flex" data-type="qq" tapmode onclick="wrapClick(this)">
        		<div class="img-box"><img src="../../image/main/dl1.png"/></div>
        		<div class="text">QQ</div>
        	</div>
        </div>
        <footer class="btn" tapmode onclick="closeClick();">取消</footer>
    </div>

</body>
<script type="text/javascript" src="../../script/base.min.js"></script>
<script type="text/javascript">

	define(function (require, exports, module) {
		pageParam = api.pageParam;
		var udata = lanYun.getStorage("UserData");
		var system = lanYun.getStorage("system");

		//分享h5的信息
		var logo = system.logo;
		var fxurl = '';
		//console.log(JSON.stringify(system));

		//-------华丽的分割线--------------------------------

		//分享小程序卡片的信息
		var page = "";
		var imgUrl = "";
		var fxtitle = "";
		if(pageParam.type == 'shop'){
			fxurl = system.fxurl_sp + '?id=' + pageParam.id +'&uid=' + udata.id;
			fxtitle = pageParam.title;
			imgUrl = pageParam.img;
		}else if (pageParam.type == 'yaoqing') {
			fxurl = system.fxurl + '?id=' + udata.id;
			fxtitle = "你的好友邀请你注册天宏商城";
			api.imageCache({
				url:logo
			}, function(ret, err) {
				imgUrl = ret.url;
			});
		}else {
			return;
		}

		wrapClick = function (tis){
	        var wxPlus = api.require('wxPlus');
			var qq = api.require('QQPlus');
			var dst = tis.dataset;
			if(dst.type == 'wxp'){
				api.imageCache({
					url:system.logo
				}, function(ret, err) {
					var blogo = ret.url;
					if(pageParam.type == 'shop'){
						blogo = imgUrl;
					}
					//分享到朋友圈
					wxPlus.isInstalled(function(ret, err) {
					    if (ret.installed) {
							wxPlus.shareWebpage({
							    scene: 'timeline',
							    title: fxtitle,
							    thumb: blogo,
							    contentUrl: fxurl,
							}, function(ret, err) {
		                        if (ret.status) {
									//lanYun.toast('分享成功');
		                        } else {
									if(err.code == 2){
										lanYun.toast("取消分享");
									}else if(err.code == 3){
										lanYun.toast("分享失败");
									}else{
										lanYun.toast(err.code);
									}
		                        }
							});
					    } else {
		                    lanYun.toast('当前设备未安装微信客户端');
					    }
					});
				});

			} else if (dst.type == 'wx') {
				api.imageCache({
					url:system.logo
				}, function(ret, err) {
					var blogo = ret.url;
					if(pageParam.type == 'shop'){
						blogo = imgUrl;
					}
					//分享给好友
					wxPlus.shareWebpage({
					    scene: 'session',
						title: fxtitle,
						thumb: blogo,
						contentUrl: fxurl,
					}, function(ret, err) {
					    if (ret.status) {
					        //lanYun.toast('分享成功');
					    } else {
							if(err.code == 2){
								lanYun.toast("取消分享");
							}else if(err.code == 3){
								lanYun.toast("分享失败");
							}else{
								lanYun.toast(err.code);
							}
					    }
					});
				});
			}else if (dst.type == 'qq') {
				qq.installed(function(ret, err) {
				    if (ret.status) {
						if(pageParam.type == 'shop'){
							logo = imgUrl;
						}
						console.log(fxtitle);
						qq.shareNews({
						    type: 'QFriend',
							url:fxurl,
						    title:fxtitle,
							imgUrl:logo,
						}, function(ret, err) {
	                        if (ret.status) {
	                            //lanYun.toast('分享成功');
	                        } else {
								if(err.code == -4){
									lanYun.toast("取消分享");
								}else{
									lanYun.toast(err.code);
								}
	                        }
						});
				    } else {
						lanYun.toast('当前设备未安装微信客户端');
				    }
				});
			}
		}

		closeClick = function(){
	        api.closeFrame();
	    };
	});

</script>
</html>
